FROM alpine:3.14

ENV PHPIZE_DEPS="autoconf dpkg-dev dpkg file tar zip g++ gcc libc-dev make pkgconf re2c pcre-dev pcre2-dev zlib-dev libtool automake"

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

COPY ./run.sh /run.sh

RUN apk update \
	&& apk add  php7 php7-pear php7-dev openssl curl bash ca-certificates libaio-dev openssl-dev curl-dev \
                php7-mysqli php7-pdo_mysql php7-mbstring php7-json php7-zlib php7-gd php7-intl php7-session php7-fpm \
                php7-curl php7-posix php7-fileinfo php7-simplexml php7-opcache php7-sodium \
                php7-tokenizer php7-ctype php7-bcmath php7-openssl php7-dom \ 
                php7-iconv php7-sockets php7-zip php7-pcntl php7-xmlwriter php7-xmlreader php7-redis php7-xml php7-phar \
                php7-pecl-event \
    && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
    && apk --no-cache add tzdata \
    && cp "/usr/share/zoneinfo/Asia/Shanghai" /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone \
    && update-ca-certificates \
    && mkdir /www \
    && sed 's/user = nobody/user = root/g' /etc/php7/php-fpm.d/www.conf | sed 's/group = nobody/group = root/g'| sed 's/127.0.0.1/0.0.0.0/g' | sed 's/pm.max_children = 5/pm.max_children = 30/g' | sed 's/pm = dynamic/pm = static/g' > /tmp/www.conf \
    && mv /tmp/www.conf /etc/php7/php-fpm.d/www.conf \
    #&& apk add gnu-libiconv libstdc++ --no-cache --repository http://mirrors.aliyun.com/alpine/edge/community/ --allow-untrusted \
    && sed 's/;opcache.enable=1/opcache.enable=1/g' /etc/php7/php.ini | sed 's/;opcache.validate_timestamps=1/opcache.validate_timestamps=0/g' | sed 's/;opcache.memory_consumption=128/opcache.memory_consumption=128/g' | sed 's/;opcache.interned_strings_buffer=8/opcache.interned_strings_buffer=8/g' | sed 's/;opcache.max_accelerated_files=10000/opcache.max_accelerated_files=10000/g' > /tmp/php.ini \
    && mv /tmp/php.ini /etc/php7/php.ini \
    && ln -s /usr/sbin/php-fpm7 /usr/sbin/php-fpm \
    #&& ln -s /usr/bin/php7 /usr/bin/php \
    #&& ln -s /usr/bin/phar7 /usr/bin/phar \
    #&& ln -s /usr/bin/php-config7 /usr/bin/php-config \
    #&& ln -s /usr/bin/phpize7 /usr/bin/phpize \
    && chmod +x /run.sh \
    && wget https://mirrors.tencent.com/composer/composer.phar \
    && mv composer.phar  /usr/local/bin/composer \
    && chmod 755 /usr/local/bin/composer \
     # ---------- clear works ----------
    #&& apk del .build-deps \
    #&& rm -rf /var/cache/apk/* /tmp/* /usr/share/man /usr/local/bin/php* \
    && composer config -g repos.packagist composer https://mirrors.tencent.com/composer/


WORKDIR /www

EXPOSE 8787 9000

CMD ["/run.sh"]